<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/7/1
 * Time: 17:18
 */
namespace common\components\helpers;
use yii\helpers\Html;
class Search extends Html{
    public static function dropDownList($name, $selection = null, $items = [], $options = [])
    {
        if (!empty($options['multiple'])) {
            return static::listBox($name, $selection, $items, $options);
        }
        $options['name'] = $name;
        unset($options['unselect']);
        $selectOptions = static::renderSelectOptions($selection, $items, $options);
        return static::html("\n" . $selectOptions . "\n", $options);
    }

    public static function textInput($name, $value = null, $options = [])
    {
        $label=!empty($options['label'])?$options['label']:'';
        $labelclass=!empty($options['labelclass'])?$options['labelclass']:'';
        $html=" <div class='yx-floatl yx-m6'><label class='zx-lh28 ".$labelclass."'>$label</label>";
        $html.=static::input('text', $name, $value, $options);
        $html.='</div>';
        return $html;
    }

    public static function activeInput($type, $model, $attribute, $options = [])
    {
        $label=!empty($options['label'])?$options['label']:'';
        $html=" <div class='yx-floatl yx-ml6'><label class='zx-lh28'>$label</label>";
        $name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
        $value = isset($options['value']) ? $options['value'] : static::getAttributeValue($model, $attribute);
        if (!array_key_exists('id', $options)) {
            $options['id'] = static::getInputId($model, $attribute);
        }
        $html.=static::input($type, $name, $value, $options);
        $html.='</div>';
        return $html;
    }

    public static function button($content = 'Button', $options = [])
    {
        if (!isset($options['type'])) {
            $options['type'] = 'button';
        }
        $html=static::tag('button', $content, $options);
        $html.='<div class="yx-clear"></div>';
        return $html;
    }

    public static function submitButton($content = 'Submit', $options = [])
    {
        $options['type'] = 'submit';
        return static::button($content, $options);
    }

    public static function html($selectOptions,$options){
        $promote=!empty($options['promote'])?$options['promote']:'';
        $class=!empty($options['class'])?'class="'.$options['class'].'"':'';
        $label=!empty($options['label'])?$options['label']:'';
        $labelclass=!empty($options['labelclass'])?$options['labelclass']:'';
        $html="<div class='yx-floatl yx-m6'> <label class='control-label yx-floatl zx-lh28 ".$labelclass."'>$label</label><div class='diy_select'>";
        $value = isset(\Yii::$app->request->get()[$options['name']])?\Yii::$app->request->get($options['name']):null;
        $html .= static::hiddenInput($options['name'],$value,['class'=>'hiddenvalue']);
        $select = "<div class='select-text zx-width150'><div $class" . static::renderTagAttributes($options) . ">$promote</div>";
        $html.=$select;
        $html.='<div class="diy_select_btn"></div></div>';
        $options = str_replace('option', 'li', $selectOptions);
        $html.='<div class="select-option"><ul class="diy_select_list">';
        $html.=$options;
        $html.='</ul> </div></div></div>';
        return $html;
    }
}